package cn.zyq.ykb.controller.mgt.product;

import org.springframework.security.access.prepost.PreAuthorize;
import cn.zyq.ykb.system.ry.util.poi.ExcelUtil;
import cn.zyq.ykb.system.common.BaseController;
import cn.zyq.ykb.system.annotation.Log;
import cn.zyq.ykb.system.ry.enums.BusinessType;
import cn.zyq.ykb.beans.product.ProductLink;
import cn.zyq.ykb.service.product.ProductLinkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.zyq.ykb.system.common.BaseController;
import cn.zyq.ykb.system.common.PageParam;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品链接Controller
 *
 * @author SystemAuth
 * @date 2023-11-02
 */

@RestController(value = "MgtProductLinkController")
@RequestMapping("/mgt/productLink")
@Api(tags = "商品链接接口")
public class ProductLinkController extends BaseController {

    @Autowired
    private ProductLinkService productLinkService;

    /**
     * 查询商品链接列表
     */
    @ApiOperation(value = "列表", response = ProductLink.class)
    @PostMapping("/list")
    public Object list(@RequestBody PageParam pageParam) {
        return this.productLinkService.selectProductLinkList(pageParam);
    }

     /**
      * 导出商品链接列表
      */
     @ApiOperation(value = "导出")
     @Log(title = "商品链接" , businessType = BusinessType.EXPORT)
     @PostMapping("/export")
     public void export(HttpServletResponse response, @RequestBody PageParam pageParam) {
         List<ProductLink> list = productLinkService.selectProductLinkAllList(pageParam);
         ExcelUtil<ProductLink> util = new ExcelUtil<ProductLink>(ProductLink. class);
         util.exportExcel(response, list, "商品链接数据");
     }

    /**
     * 获取商品链接详细信息
     */
    @ApiOperation(value = "详情", response = ProductLink.class)
    @GetMapping(value = "/{productLinkID}")
    public Object getInfo(@PathVariable("productLinkID") Integer productLinkID) {
        return this.productLinkService.selectProductLinkByProductLinkID(productLinkID);
    }
    /**
     * 获取商品链接详细信息
     */
    @ApiOperation(value = "详情", response = ProductLink.class)
    @GetMapping(value = "/detail/{serviceID}")
    public Object getInfo(@PathVariable(value = "serviceID") String serviceID) {
        return this.productLinkService.selectProductLinkByServiceID(serviceID);
    }

    /**
     * 新增商品链接
     */
    @ApiOperation(value = "新增")
    @Log(title = "商品链接", businessType = BusinessType.INSERT)
    @PostMapping
    public Object add(@RequestBody ProductLink productLink) {
        return this.productLinkService.insertProductLink(productLink);
    }

    /**
     * 修改商品链接
     */
    @ApiOperation(value = "编辑")
    @Log(title = "商品链接", businessType = BusinessType.UPDATE)
    @PutMapping
    public Object edit(@RequestBody ProductLink productLink) {
        return this.productLinkService.updateProductLink(productLink);
    }

    /**
     * 删除商品链接
     */
    @ApiOperation(value = "删除")
    @Log(title = "商品链接", businessType = BusinessType.DELETE)
    @DeleteMapping("/{productLinkIDs}")
    public Object remove(@PathVariable Integer[] productLinkIDs) {
        return this.productLinkService.deleteProductLinkByProductLinkIDs(productLinkIDs);
    }
}
